from importlib.metadata import version
from typing import List

from src.bean.config_column_enum import ConfigColumnEnum
from src.bean.key_func import KeyFunc
from src.extract.abnormal import extract_abnormal_entrance
from src.extract.normal import extract_normal_entrance
from src.model.model_operation import model_operation_entrance
from src.other.merge_file import merge_files_entrance
from src.other.process_statistic import process_statistic_entrance
from src.other.split_file import split_files_entrance
from src.other.update_entrance import update_entrance
from src.print_columns import print_columns_entrance
from src.test.test_entrance import run_test_entrance
from src.util.common_util import update_local_cache, init_cache, input_is_yes, loop_exe
from src.util.config_manager import ConfigManager
from src.util.csv_util import csv_entrance
from src.util.scp_util import scp_entrance

if __name__ == '__main__':
    if int(version("xbase_util").replace(".", "")) < 135:
        print("xbase_util版本请用 pip install 1.3.5  以上的版本")
    else:
        config = ConfigManager()
        data_cache, data_path = init_cache()
        config.set_config(ConfigColumnEnum.data_cache.value, data_cache)
        config.set_config(ConfigColumnEnum.data_path.value, data_path)
        config.set_config(ConfigColumnEnum.use_terminal.value, input_is_yes("[初始化]是否终端运行"))
        map_list: List[KeyFunc] = [
            KeyFunc(key='[提取]正常数据', func=extract_normal_entrance),
            KeyFunc(key='[提取]异常数据', func=extract_abnormal_entrance),
            KeyFunc(key='[提取]查看提取过程', func=print_columns_entrance),
            KeyFunc(key='[工具]统计进程', func=process_statistic_entrance),
            KeyFunc(key='[工具]统计csv总量', func=csv_entrance),
            KeyFunc(key='[工具]合并文件', func=merge_files_entrance),
            KeyFunc(key='[工具]拆分文件', func=split_files_entrance),
            KeyFunc(key='[功能]模型操作', func=model_operation_entrance),
            KeyFunc(key='[功能]更新缓存', func=update_local_cache),
            KeyFunc(key='[功能]运行测试代码', func=run_test_entrance),
            KeyFunc(key='[功能]更新程序', func=update_entrance),
            KeyFunc(key='[功能]传文件', func=scp_entrance),
            KeyFunc(key='[退出程序]', func=None),
        ]
        loop_exe(map_list, config)
